package javaer.starter.core.render;

import javaer.starter.base.domain.dto.TemplateDTO;
import javaer.starter.constant.BuiltInPlaceHolder;
import javaer.starter.constant.FileExtensionEnum;
import javaer.starter.constant.SymbolEnum;
import javaer.starter.core.handler.ModuleContext;
import org.springframework.stereotype.Component;

import java.io.File;

/**
 * java文件的处理器
 *
 * @author yangzhen
 * @date 2023/6/14 19:03
 * @since 1.0.0
 */
@Component
public class JavaFileTemplateRender implements ISuffixFileRender {

    @Override
    public String getMatchToken() {
        return FileExtensionEnum.JAVA.getValue();
    }

    @Override
    public void inject(ModuleContext moduleContext, Object... args) {
        TemplateDTO arg = (TemplateDTO) args[0];

        // 相对路径
        String relativePath = arg.getRelativePath();
        String relativePackage = relativePath.replace(File.separatorChar, '.');
        // 模块的包
        moduleContext.getTempValues().put(BuiltInPlaceHolder.package_this_file.name(), moduleContext.getBasePackage() + SymbolEnum.POINT.getSymbol() + relativePackage);
    }

    @Override
    public boolean needBasePackagePath() {
        return true;
    }
}
